# --*-- coding:utf-8 --*--
import ssl

ssl.create_default_context(purpose=ssl.Purpose.SERVER_AUTH)

from qcloudsms_py import SmsMultiSender, SmsSingleSender
from qcloudsms_py.httpclient import HTTPError
from django.conf import settings

def send_sms_single(phone_num, template_id, template_parm_list):
    """
    :param phone_num: 手机号
    :param template_id: 腾讯云短信模板ID
    :param template_parm_list: 短信模板参数列表：例如【验证码：{1}，描述{2}】
    :return:
    """
    # 自己应用ID
    appid = settings.TENCENT_SMS_APP_ID
    # 自己应用key
    appkey = settings.TENCENT_SMS_APP_KEY
    # 短信内容
    sms_sign = settings.TENCENT_SMS_SIGN

    sender = SmsSingleSender(appid, appkey)
    try:
        response = sender.send_with_param(86, phone_num, template_id, template_parm_list, sign = sms_sign)
    except HTTPError as e:
        response = {'result': 1000, 'errmsg':"网络异常发送失败"}
    return response

def send_sms_multi(phone_num_list, template_id, parm_list):
    """
        :param phone_num: 手机号
        :param template_id: 腾讯云短信模板ID
        :param template_parm_list: 短信模板参数列表：例如[验证码：{1}，描述{2}]
        :return:
        """
    appid = 1400621326  # 自己应用ID
    appkey = "7ae9e726030f44cc19840dbbfdc7bd6f"  # 自己应用key
    sms_sign = "辉毅美好"  # 短信内容,微信公众号名称
    sender = SmsMultiSender(appid, appkey)
    try:
        response = sender.send_with_param(86, phone_num_list, template_id, parm_list, sign = sms_sign)
    except HTTPError as e:
        response = {'result': 1000, 'errmsg':"网络异常发送失败"}
    return response

if __name__ == '__main__':
    #result1 = send_sms_single("18842834556",1276452, [666,])
    #print(result1)

    result2 = send_sms_multi(["18842834556","15712399578"], 1276452, [999, ])
    print(result2)

